//
//  bigImgCell.m
//  bigImgTest
//
//  Created by apple on 2017/9/30.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "bigImgCell.h"
#import <UIImageView+WebCache.h>
#define kWidth [UIScreen mainScreen].bounds.size.width
#define kHeight [UIScreen mainScreen].bounds.size.height
#define imgh (kHeight / 1.7)
@implementation bigImgCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, -(imgh -240)/2, kWidth, imgh)];
    
    self.imgView.contentMode = UIViewContentModeScaleAspectFill;
    [self.contentView insertSubview:_imgView atIndex:0];
    self.clipsToBounds = YES;
}



- (void)setModel:(EveryDayModel *)model{
    
    if (_model != model) {
        
        [_imgView sd_setImageWithURL:[NSURL URLWithString:model.coverForDetail] placeholderImage:nil];
        
        _titLB.text = model.title;
        
        // 转换时间
        NSInteger time = [model.duration integerValue];
        
        NSString *timeString = [NSString stringWithFormat:@"%02ld'%02ld''",time/60,time% 60];//显示的是音乐的总时间
        
        NSString *string = [NSString stringWithFormat:@"#%@ / %@",model.category, timeString];
        
        _titLB.text = string;
    }
    
}


- (CGFloat)cellOffset {
    
    CGRect centerToWindow = [self convertRect:self.bounds toView:self.window];
    
    CGFloat centerY = CGRectGetMidY(centerToWindow);
    CGPoint windowCenter = self.superview.center;
    
    CGFloat cellOffsetY = centerY - windowCenter.y;
    
    CGFloat offsetDig =  cellOffsetY / self.superview.frame.size.height *2;
     CGFloat offset =  - offsetDig * (imgh - 240)/2;
    
    CGAffineTransform transY = CGAffineTransformMakeTranslation(0,offset);
    
    self.imgView.transform = transY;
    
    return offset;
    
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
